package com.cart;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;


@ManagedBean
@SessionScoped
public class ItemBean implements Serializable {

        /**
         * 
         */
        private static final long serialVersionUID = 1L;
        
        private List<ItemTo> dispList;
        private int num;
        private ItemTo selectedItm;
       
        
        public void rowgen(int event){
                System.out.println(event);
                for(int i=0;i<event;i++){
                        Constants.itemList.add(new ItemTo(Constants.itemList.size()+1));
                }
                setDispList(Constants.itemList);
                if(event >0)
                    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,"Info :", event +" blank Rows has been added in the table"));
        }
        
        
        

        public void update(List<ItemTo> list){
        		
                List a = Constants.itemList;
                System.out.println(a.size());
                setNum(0);
                //FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,"Info :", "Data has been Saved....")); 
                
        }
        
        public void deleteItm(ItemTo tempTo){
        	
            //System.out.println(selectedItm.getItemId());
            //ItemTo tempTo = dispList.get(selectedItm.getItemId()-1);
            if(tempTo != null){
            	tempTo.setItemDesc(null);
            	tempTo.setItemName(null);
            	tempTo.setProduct(null);
            	tempTo.setItemQty(1);
            	tempTo.setShipDate(null);
            	tempTo.setTotalPrice(0);
            	tempTo.setUnitPrice(0);
            	tempTo.setListPrice(0);
            	getDispList().set(tempTo.getItemId()-1, tempTo);
            	setDispList(getDispList());
            }
        }
        
        
       
        
        
        
        public int getNum() {
                return num;
        }


        public void setNum(int num) {
                this.num = num;
        }

        public List<ItemTo> getDispList() {
                return Constants.itemList;
        }

        public void setDispList(List<ItemTo> dispList) {
                this.dispList = dispList;
        }

    /**
     * @return the selectedItm
     */
    public ItemTo getSelectedItm() {
        return selectedItm;
    }

    /**
     * @param selectedItm the selectedItm to set
     */
    public void setSelectedItm(ItemTo selectedItm) {
        this.selectedItm = selectedItm;
    }




	
        

}
